<?

		if($_REQUEST['act'] == "edit" && $_REQUEST['cmd'] == "true")
		{
			$valuearray['tp_name'] = $_POST['tp_name'];
			$valuearray['tp_name2'] = $_POST['tp_name2'];
			$valuearray['tp_dese'] = $_POST['description'];
			$valuearray['tp_dese2'] = $_POST['description2'];
			
			if($_POST['pdzize']) foreach($_POST['pdzize'] as $a)  $valuearray['tp_size'] .= $a."|";
			Qupdate("topic",'',$valuearray," tp_id=".$_POST['tp_id'] );
			exit("<script type=\"text/javascript\">window.location='?body=sidebardes&act=edit';</script>");
		}
		else if($_REQUEST['act'] == "add" && $_REQUEST['cmd'] == "true")
		{
			//print_r($_POST);
			$maxorder = Q1("select MAX(tp_order) from topic  ");
			$valuearray['tp_name'] = $_POST['tp_name'];
			$valuearray['tp_name2'] = $_POST['tp_name2'];
			$valuearray['tp_dese'] = $_POST['description'];
			$valuearray['tp_dese2'] = $_POST['description2'];
			$valuearray['tp_func'] = $_POST['tp_func'];
			$valuearray['c_id'] = $_REQUEST['c_id'];			
			Qinsert("topic","",$valuearray);
		}
		else if($_REQUEST['swap1'] >= 1 && $_REQUEST['swap2'] >= 1)
		{
				$r1 = Q1("select tp_id,tp_order from topic  where tp_id =   ".$_REQUEST['swap1']);
				$r2 = Q1("select tp_id,tp_order from topic  where tp_id =   ".$_REQUEST['swap2']);
				mysql_query("update topic set tp_order = '".$r2['tp_order']."' where tp_id = '".$r1['tp_id']."'  ");
				mysql_query("update topic set tp_order = '".$r1['tp_order']."' where tp_id = '".$r2['tp_id']."'  ");
		}
		else if($_REQUEST['delid'] >= 1)
		{
			mysql_query("DELETE FROM `topic` WHERE `topic`.`tp_id` = '".$_REQUEST['delid']."' LIMIT 1");

			$del1 = Q2("select img_pic from images where na_id = '".$_REQUEST['delid']."' and tables='topic' ");
			foreach($del1 as $del)
			{
				@unlink("../imgs/".$del['img_pic']);
				@unlink("../imgs/".str_replace(".","-swap.",$del['img_pic']));
				@unlink("../imgs/".str_replace(".","-tmp.",$del['img_pic']));
			}
			mysql_query("DELETE FROM `images` WHERE `images`.`na_id` = ".$_REQUEST['delid']."  ");			
		}
?>


<script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
<?
$r = Q1("select * from topic where tp_func = 'sidebardes' ");
if($r == null){
		$_REQUEST['act'] = "add";
}else{
		$_REQUEST['act'] = "edit";
}
$rx = Q1("select * from language limit 1");
?>			
            <fieldset>
            <legend>Step 2 : Sidebar topic box</legend>
            <form action="" method="post" name="a">
            
            <input name="tp_name" type="hidden" value="sidebardes" /><input name="tp_name2" type="hidden" value="sidebardes" />
            
            <label>Sidebar topic description : </label> <br> <?=$rx[lang1]?> <br> <br>
			<textarea name="description" ><?=$r['tp_dese']?></textarea>
			<Br><br> <?=$rx[lang2]?> <br><br> 
			<textarea name="description2" ><?=$r['tp_dese2']?></textarea>

           <br /><br /><br /> <input name="submit" type="submit" value="<?=btsubmit($r['tp_id'])?>" />
            <input name="c_id" type="hidden" value="<?=$_REQUEST['c_id']?>" />
            <input name="tp_func" type="hidden" value="sidebardes" />
            <input name="cmd" type="hidden" value="true" />
            <input name="act" type="hidden" value="<? ($_REQUEST['act'] == "")? print "add":print $_REQUEST['act'];?>" />
            <input name="tp_id" type="hidden" value="<?=$r['tp_id']?>" />
            </form>
            </fieldset>
            
	<br />
<br />
        
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script>

var path = "/admin/js";	
CKEDITOR.replace( 'description' ,{
	filebrowserBrowseUrl : path+'/ckfinder/ckfinder.html',
    filebrowserImageBrowseUrl : path+'/ckfinder/ckfinder.html?Type=Images',
    filebrowserFlashBrowseUrl : path+'/ckfinder/ckfinder.html?Type=Flash',
    filebrowserUploadUrl : path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
    filebrowserImageUploadUrl :path+ '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
    filebrowserFlashUploadUrl : path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
	width:500,
	height:200
	
	});
	CKEDITOR.replace( 'description2' ,{
	filebrowserBrowseUrl : path+'/ckfinder/ckfinder.html',
    filebrowserImageBrowseUrl : path+'/ckfinder/ckfinder.html?Type=Images',
    filebrowserFlashBrowseUrl :path+ '/ckfinder/ckfinder.html?Type=Flash',
    filebrowserUploadUrl : path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
    filebrowserImageUploadUrl :path+ '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
    filebrowserFlashUploadUrl :path+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
	width:500,
	height:200
	});
	
	$('input[name=tp_promo1]').live('click',function(){
			$('#promo_panel').toggle('fast');
			
			
			if($('input[name=tp_promo1]').attr('checked') == "checked"){
			//alert('check'+$('#all_checked').attr('checked'));
			$('input[name=tp_promo]').val(1);
		}else{
			//alert('uncheck'+$('#all_checked').attr('checked'));	
			$('input[name=tp_promo]').val(0);
		}
	});
</script>
